#!/bin/sh

COREWIFI="$1"
VIDEO="$2"
LANG="$3"
VERSION="$(cat data/eversion)"
ISODIR="/mnt/sda2/eCore"
TESTDIR="/mnt/sda1/boot/iso"
THISDIR=`pwd`
[ "$LANG" ] && LANG=_$LANG
if [ "$COREWIFI" = "core" ];then
	case "$VIDEO" in
		no3d) 	CFG="${THISDIR}/eCore$LANG.cfg"
			ISO="${ISODIR}/eCore$LANG-$VERSION.iso";;
		3d)	CFG="${THISDIR}/eCore3d$LANG.cfg"
			ISO="${ISODIR}/eCore3d$LANG-$VERSION.iso";;
		xvesa)	CFG="${THISDIR}/eCorexvesa$LANG.cfg"
			ISO="${ISODIR}/eCorexvesa$LANG-$VERSION.iso";;
		esac
else #wifi
	case "$VIDEO" in
		no3d) 	CFG="${THISDIR}/eCorewifi$LANG.cfg"
			ISO="${ISODIR}/eCorewifi$LANG-$VERSION.iso";;
		3d)	CFG="${THISDIR}/eCore3dwifi$LANG.cfg"
			ISO="${ISODIR}/eCore3dwifi$LANG-$VERSION.iso";;
		xvesa)	CFG="${THISDIR}/eCorexvesawifi$LANG.cfg"
			ISO="${ISODIR}/eCorexvesawifi$LANG-$VERSION.iso";;
		esac

fi
echo CFG=$CFG
echo ISO=$ISO
#exit
#echo -n "Press Enter key."
#read gagme
if [ ! -f /usr/local/tce.installed/ezremaster ]; then
   if [ ! -e /etc/sysconfig/tcedir/optional/ezremaster.tcz ]; then
      tce-load -w ezremaster
   fi
      tce-load -is ezremaster
fi
sudo rm -rf ezremaster/*
remaster.sh $CFG checkimage
remaster.sh $CFG extractimage
#echo -n "Next bootcode.Press Enter key."
#read gagme
remaster.sh $CFG bootcode
#echo -n "Press Enter key."
#read gagme
remaster.sh $CFG apps
if [ "$LANG" = "_it" ];then 
   sudo cp data/boot_it.msg ezremaster/image/boot/isolinux/boot.msg
else
   sudo cp data/boot.msg ezremaster/image/boot/isolinux
   sudo cp data/boot.msg ezremaster/image/boot/isolinux/f1
fi
sudo cp onboot/*.lst 			ezremaster/image/cde
sudo cp data/copy2fs.lst 		ezremaster/image/cde
sudo cp data/tc-config   		ezremaster/extract/etc/init.d/
sudo cp data/e-tc-functions   		ezremaster/extract/etc/init.d/
sudo cp data/tce-setup   		ezremaster/extract/usr/bin/
sudo cp data/fromISOfile 		ezremaster/extract/usr/bin/
sudo cp data/filetool.sh 		ezremaster/extract/usr/bin/
sudo cp data/eversion    		ezremaster/extract/usr/share/doc/tc/erelease.txt
sudo cp data/eCore.edj    		ezremaster/extract/usr/local/share/exquisite/data/themes/
sudo cp data/.xsession    		ezremaster/extract/etc/skel/
sudo cp data/entrance.conf    		ezremaster/extract/usr/local/etc/entrance.conf
echo "(sleep 0.7 && eeze_scanner) &">>	ezremaster/extract/opt/bootlocal.sh
#echo -n "Press Enter key."
#read gagme
remaster.sh $CFG package
cp ezremaster/ezremaster.iso "$TESTDIR"
mv ezremaster/ezremaster.iso "$ISO"
